<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园宿舍管理系统 - 学生列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark " style="background-color: #17a589;">
    <div class="container">
        <a class="navbar-brand" href="#">校园宿舍管理系统</a>
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/home}">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" th:href="@{/student/list}">学生管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/dormitory/list}">宿舍管理</a>
                </li>
            </ul>
            <div class="d-flex">
                <span class="navbar-text me-3" th:text="'欢迎，' + ${session.user.username}"></span>
                <a class="btn btn-outline-light" th:href="@{/user/logout}">退出</a>
            </div>
        </div>
    </div>
</nav>
<div class="container mt-4">
    <div class="row mb-3">
        <div class="col-md-6">
            <h2>学生列表</h2>
        </div>
        <div class="col-md-6 text-end">
            <a class="btn btn-primary" th:href="@{/student/add}">添加学生</a>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-md-6">
            <form th:action="@{/student/search}" method="get" class="d-flex">
                <input type="text" name="name" class="form-control me-2" placeholder="搜索学生姓名">
                <button type="submit" class="btn btn-outline-secondary">搜索</button>
            </form>
        </div>
    </div>

    <table class="table table-striped table-hover">
        <thead>
        <tr>
            <th>ID</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>班级</th>
            <th>专业</th>
            <th>宿舍</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="student : ${students}">
            <td th:text="${student.id}"></td>
            <td th:text="${student.name}"></td>
            <td th:text="${student.gender}"></td>
            <td th:text="${student.age}"></td>
            <td th:text="${student.className}"></td>
            <td th:text="${student.major}"></td>
            <td th:text="${student.dormitoryNumber != null && !student.dormitoryNumber.isEmpty()} ? ${student.dormitoryNumber} : '未分配'"></td>
<!--            <td th:text="${student.dormitoryNumber != null ? student.dormitoryNumber : '未分配'}"></td>-->
            <td>
                <a th:href="@{/student/edit/{id}(id=${student.id})}" class="btn btn-sm btn-outline-primary">编辑</a>
                <a th:href="@{/student/delete/{id}(id=${student.id})}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定删除吗？')">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>